<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="en">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="已经有现成的第三方博客了，为什么还要自己折腾？ 中文社区有很多博客托管的网站，例如CSDN, 博客园，简书等等。与此同时，还有一些笔记类的工具可供选择，例如印像笔记，OneNote等等。但是，今天这些都不是我们讨论的重点，我们今天的重点是讨论一下如何利用Hexo, Github和Travis-CI来搭建并且自动化布署我们的个人博客，那么这样做的好处是什么呢？我想到了以下几点：  避免各大博客门户网">
<meta property="og:type" content="article">
<meta property="og:title" content="Hexo搭配Github与Travis-Ci搭建个人博客">
<meta property="og:url" content="http://yoursite.com/2020/07/24/Hexo%E6%90%AD%E9%85%8DGithub%E4%B8%8ETravis-Ci%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/index.html">
<meta property="og:site_name" content="LinRaise&#39;s Blog">
<meta property="og:description" content="已经有现成的第三方博客了，为什么还要自己折腾？ 中文社区有很多博客托管的网站，例如CSDN, 博客园，简书等等。与此同时，还有一些笔记类的工具可供选择，例如印像笔记，OneNote等等。但是，今天这些都不是我们讨论的重点，我们今天的重点是讨论一下如何利用Hexo, Github和Travis-CI来搭建并且自动化布署我们的个人博客，那么这样做的好处是什么呢？我想到了以下几点：  避免各大博客门户网">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="http://yoursite.com/2020/07/24/Hexo%E6%90%AD%E9%85%8DGithub%E4%B8%8ETravis-Ci%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/image-20200727110730633.png">
<meta property="og:image" content="http://yoursite.com/2020/07/24/Hexo%E6%90%AD%E9%85%8DGithub%E4%B8%8ETravis-Ci%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/image-20200727114001930.png">
<meta property="og:image" content="http://yoursite.com/2020/07/24/Hexo%E6%90%AD%E9%85%8DGithub%E4%B8%8ETravis-Ci%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/image-20200727155149660.png">
<meta property="og:image" content="http://yoursite.com/2020/07/24/Hexo%E6%90%AD%E9%85%8DGithub%E4%B8%8ETravis-Ci%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/image-20200727161447684.png">
<meta property="og:image" content="http://yoursite.com/2020/07/24/Hexo%E6%90%AD%E9%85%8DGithub%E4%B8%8ETravis-Ci%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/image-20200727161059567.png">
<meta property="article:published_time" content="2020-07-24T14:45:25.000Z">
<meta property="article:modified_time" content="2020-07-24T14:45:25.000Z">
<meta property="article:author" content="LinRaise">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://yoursite.com/2020/07/24/Hexo%E6%90%AD%E9%85%8DGithub%E4%B8%8ETravis-Ci%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/image-20200727110730633.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"right","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2020/07/24/Hexo搭配Github与Travis-Ci搭建个人博客/"/>





  <title>Hexo搭配Github与Travis-Ci搭建个人博客 | LinRaise's Blog</title>
  








<meta name="generator" content="Hexo 4.2.1"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="en">

  
  
    
  

  <div class="container sidebar-position-right page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">LinRaise's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            About
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            Tags
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            Archives
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            Search
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="Searching..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/07/24/Hexo%E6%90%AD%E9%85%8DGithub%E4%B8%8ETravis-Ci%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="LinRaise">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="LinRaise's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Hexo搭配Github与Travis-Ci搭建个人博客</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2020-07-24T14:45:25+00:00">
                2020-07-24
              </time>
            

            
              <span class="post-meta-divider">|</span>
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-check-o"></i>
              </span>
              
                <span class="post-meta-item-text">Post modified&#58;</span>
              
              <time title="Post modified" itemprop="dateModified" datetime="2020-07-24T14:45:25+00:00">
                2020-07-24
              </time>
            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><strong>已经有现成的第三方博客了，为什么还要自己折腾？</strong></p>
<p>中文社区有很多博客托管的网站，例如CSDN, 博客园，简书等等。与此同时，还有一些笔记类的工具可供选择，例如印像笔记，OneNote等等。但是，今天这些都不是我们讨论的重点，我们今天的重点是讨论一下如何利用Hexo, Github和Travis-CI来搭建并且自动化布署我们的个人博客，那么这样做的好处是什么呢？我想到了以下几点：</p>
<ol>
<li>避免各大博客门户网站的广告植入。</li>
<li>更加的极客风格，完全以源代码的方式管控我们自己的博客，迁移和改动都十分便利。</li>
<li>由于Hexo的博客风格样式十分的清新简洁，因此，十分适合我的品味。</li>
<li>Travis-CI自动集成自动发布的特点，因此，管控文章的方式十分的优雅。</li>
</ol>
<p><strong>Hexo+Github+Travis-Ci的工作原理是什么呢？</strong></p>
<p>Hexo是一个Node.js的项目，主要是将Markdown语法的文章渲染并生成静态的HTML页面，</p>
<p>再通过Github Pages将静态的HTML显示出来可以达到博客的效果，</p>
<p>而Travis-Ci的作用主要是根据Github的提交实时触发Hexo的解释并生成静态页面，无需人工参与发布操作。</p>
<p><strong>软件依赖：</strong></p>
<ol>
<li>Node.js</li>
<li>Git</li>
<li>TortoiseGit (可选)</li>
</ol>
<p>首先需要先申请一下Github帐号,</p>
<p>访问<code>https://github.com/</code>⟶<code>Sign up</code></p>
<img src="/2020/07/24/Hexo%E6%90%AD%E9%85%8DGithub%E4%B8%8ETravis-Ci%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/image-20200727110730633.png" alt="image-20200727110730633" style="zoom:70%;">

<p>新建一个<code>公有</code>项目，<code>{account-name}</code>.github.io，在本文中是<code>hexoblog1.github.io</code>,这个仓库主要是托管<code>公有</code>的静态HTML页面。</p>
<img src="/2020/07/24/Hexo%E6%90%AD%E9%85%8DGithub%E4%B8%8ETravis-Ci%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/image-20200727114001930.png" alt="image-20200727114001930" style="zoom: 70%;">

<p>新建一个<code>私有</code>项目<code>hexoblog1</code>,这个仓库主要是托管<code>私有</code>的Markdown源文件，因为无须对外公布源文件。</p>
<img src="/2020/07/24/Hexo%E6%90%AD%E9%85%8DGithub%E4%B8%8ETravis-Ci%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/image-20200727155149660.png" alt="image-20200727155149660" style="zoom:70%;">

<p>还有一件很重要的事情，需要为github仓库生成token，Travis-ci需要根据github生成的token来访问github的代码仓库。</p>
<p>访问<a href="https://github.com/settings/tokens⟶`Generate" target="_blank" rel="noopener">https://github.com/settings/tokens⟶`Generate</a> new token`，起名GH_TOKEN，需要在生成的时候复制出来，因为这个TOKEN只会在生成的时候显示。</p>
<p><img src="/2020/07/24/Hexo%E6%90%AD%E9%85%8DGithub%E4%B8%8ETravis-Ci%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/image-20200727161447684.png" alt="image-20200727161447684"></p>
<p>拥有了TOKEN之后，使用Github帐号登录<a href="https://travis-ci.com/⟶`Sign" target="_blank" rel="noopener">https://travis-ci.com/⟶`Sign</a> In<code>⟶</code>SIGN IN WITH GITHUB<code>⟶ 选中托管源文件的</code>hexoblog1<code>仓库⟶</code>More Options<code></code>Settings`⟶添加环境变量GH_TOKEN，（VALUE就是上一步GITHUB生成的TOKEN值）用于访问github仓库</p>
<blockquote>
<p>注意：不要勾选DISPLAY VALUE IN BUILD LOG, 避免在Travis-CI的Build日志中导致token泄露<br>注意：这里不能访问<a href="https://travis-ci.org,因为这个网站目前并不能支持私有仓库。" target="_blank" rel="noopener">https://travis-ci.org,因为这个网站目前并不能支持私有仓库。</a></p>
</blockquote>
<p><img src="/2020/07/24/Hexo%E6%90%AD%E9%85%8DGithub%E4%B8%8ETravis-Ci%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/image-20200727161059567.png" alt="image-20200727161059567"></p>
<p>至此，Travis-CI与Github仓库的连接已经通过GH_TOKEN建立起来了，下面着重讨论Hexo的配置，执行以下命令生成基本的Hexo 博客框架；</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-cli -g <span class="comment">/**install scaffolding**/</span></span><br><span class="line">hexo init hexoblog1		<span class="comment">/**initial the blog by clone from remote github repository**/</span></span><br><span class="line">cd hexoblog1			<span class="comment">/**go to the blog folder**/</span></span><br><span class="line">npm install				<span class="comment">/**install the project**/</span></span><br><span class="line">hexo server				<span class="comment">/**start the server**/</span></span><br></pre></td></tr></table></figure>

<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">(node:9296)</span> <span class="attr">ExperimentalWarning:</span> <span class="string">The</span> <span class="string">fs.promises</span> <span class="string">API</span> <span class="string">is</span> <span class="string">experimental</span></span><br><span class="line"><span class="string">INFO</span>  <span class="string">Start</span> <span class="string">processing</span></span><br><span class="line"><span class="string">INFO</span>  <span class="string">Hexo</span> <span class="string">is</span> <span class="string">running</span> <span class="string">at</span> <span class="string">http://localhost:4000</span> <span class="string">.</span> <span class="string">Press</span> <span class="string">Ctrl+C</span> <span class="string">to</span> <span class="string">stop.</span></span><br></pre></td></tr></table></figure>

<p>访问<a href="http://localhost:4000可以看到默认的hexo为我们生成的页面。">http://localhost:4000可以看到默认的hexo为我们生成的页面。</a></p>
<p>参考这篇</p>
<p>添加Travis-Ci必需的<code>.travis.yml</code>配置文件，<code>yaml-1</code></p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">sudo:</span> <span class="literal">false</span></span><br><span class="line"><span class="attr">language:</span> <span class="string">node_js</span></span><br><span class="line"><span class="attr">node_js:</span></span><br><span class="line">  <span class="bullet">-</span> <span class="number">10</span> <span class="comment"># use nodejs v10 LTS</span></span><br><span class="line"><span class="attr">cache:</span> <span class="string">npm</span></span><br><span class="line"><span class="attr">branches:</span></span><br><span class="line">  <span class="attr">only:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="string">master</span> <span class="comment"># build hexo branch only</span></span><br><span class="line"><span class="attr">script:</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">hexo</span> <span class="string">generate</span> <span class="comment"># generate static files</span></span><br><span class="line"><span class="attr">deploy:</span></span><br><span class="line">  <span class="attr">provider:</span> <span class="string">pages</span></span><br><span class="line">  <span class="attr">skip-cleanup:</span> <span class="literal">true</span>                    <span class="comment"># Make sure you have skip_cleanup set to true, otherwise Travis CI will delete all the files created during the build, which will probably delete what you are trying to upload.</span></span><br><span class="line">  <span class="attr">local-dir:</span> <span class="string">public</span>                     <span class="comment"># Directory to push to GitHub Pages, defaults to current directory. Can be specified as an absolute path or a relative path from the current directory.</span></span><br><span class="line">  <span class="attr">target-branch:</span> <span class="string">master</span>                 <span class="comment"># Branch to (force, see: keep_history) push local_dir contents to, defaults to gh-pages.</span></span><br><span class="line">  <span class="attr">repo:</span> <span class="string">hexoblog1/hexoblog1.github.io</span>   <span class="comment"># Repo slug, defaults to current repo. <span class="doctag">Note:</span> The slug consists of username and repo name and is formatted like user/repo-name.</span></span><br><span class="line">  <span class="attr">github-token:</span> <span class="string">$GH_TOKEN</span>               <span class="comment"># Set in the settings page of your repository, as a secure variable</span></span><br><span class="line">  <span class="attr">keep-history:</span> <span class="literal">false</span>                   <span class="comment"># Optional, create incremental commit instead of doing push force, defaults to false.</span></span><br><span class="line">  <span class="attr">on:</span></span><br><span class="line">    <span class="attr">branch:</span> <span class="string">master</span>                      <span class="comment"># source code branch</span></span><br></pre></td></tr></table></figure>

<p>以上是以Travis-CI默认提供的provider来实现推送，我们也可以通过自定义脚本来实现相同的目的，如下：<code>yaml-2</code></p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">sudo:</span> <span class="literal">false</span></span><br><span class="line"><span class="attr">language:</span> <span class="string">node_js</span></span><br><span class="line"><span class="attr">node_js:</span></span><br><span class="line">  <span class="bullet">-</span> <span class="number">10</span> <span class="comment"># use nodejs v10 LTS</span></span><br><span class="line"><span class="attr">cache:</span> <span class="string">npm</span></span><br><span class="line"><span class="attr">branches:</span></span><br><span class="line">  <span class="attr">only:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="string">master</span> <span class="comment"># build hexo branch only</span></span><br><span class="line"><span class="attr">script:</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">hexo</span> <span class="string">generate</span> <span class="comment"># generate static files</span></span><br><span class="line"><span class="attr">after_script:</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">cd</span> <span class="string">./public</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">git</span> <span class="string">init</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">git</span> <span class="string">config</span> <span class="string">user.name</span> <span class="string">"Deployment Bot"</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">git</span> <span class="string">config</span> <span class="string">user.email</span> <span class="string">"deploy@travis-ci.org"</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">git</span> <span class="string">add</span> <span class="string">.</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">git</span> <span class="string">commit</span> <span class="string">-m</span> <span class="string">"deploy $&#123;GH_REPO&#125;"</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">git</span> <span class="string">push</span> <span class="string">--force</span> <span class="string">--quiet</span> <span class="string">"https://$&#123;GH_TOKEN&#125;@$&#123;GH_REPO&#125;"</span> <span class="string">master:master</span></span><br><span class="line"><span class="attr">branches:</span></span><br><span class="line">  <span class="attr">only:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="string">master</span></span><br><span class="line"><span class="attr">env:</span></span><br><span class="line"> <span class="attr">global:</span></span><br><span class="line">   <span class="bullet">-</span> <span class="attr">GH_REPO:</span> <span class="string">github.com/hexoblog1/hexoblog1.github.io.git</span></span><br></pre></td></tr></table></figure>

<p>至此，一个完整的Hexo+Github+Travis-CI的链路就已经建好了，但是博客显示的效果还不是很好，接下来我们需要做一些优化；</p>
<ol>
<li>把博客主题换成Next; </li>
</ol>
<p>   安装next主题只需要clone最新的next项目到themes目录下即可，</p>
   <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> <span class="built_in">cd</span> your-hexo-site</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> git <span class="built_in">clone</span> https://github.com/iissnan/hexo-theme-next themes/next</span></span><br></pre></td></tr></table></figure>

<p>   启用next主题，需要修改根目录的配置文件<code>_config.yml</code>，同时定制一些个性化内容，如下</p>
   <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">theme: next</span><br><span class="line">title: Hexoblog1</span><br><span class="line">author: hexoblog1</span><br><span class="line">post_asset_folder: true</span><br><span class="line">use_date_for_updated: true</span><br></pre></td></tr></table></figure>

<p>   同时我们还想添加博客搜索查询功能，在根目录下执行以下命令安装<code>hexo-generator-searchdb</code></p>
   <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-generator-searchdb --save</span><br></pre></td></tr></table></figure>

<p>   添加以下内容到根目录的配置文件<code>_config.yml</code></p>
   <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">search:</span><br><span class="line">    path: search.xml</span><br><span class="line">    field: post</span><br><span class="line">    format: html</span><br><span class="line">    limit: 10000</span><br></pre></td></tr></table></figure>

<p>   在<code>themes/next/_config.yml</code>中启用本地搜索</p>
   <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">local_search:</span><br><span class="line">  enable: true</span><br></pre></td></tr></table></figure>

<p>   选择 Scheme需要切换到<code>/themes/next_config.yml</code>,修改为以下配置，我选择的是Gemini</p>
   <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"># ---------------------------------------------------------------</span><br><span class="line"># Scheme Settings</span><br><span class="line"># ---------------------------------------------------------------</span><br><span class="line"></span><br><span class="line"># Schemes</span><br><span class="line">#scheme: Muse</span><br><span class="line">#scheme: Mist</span><br><span class="line">#scheme: Pisces</span><br><span class="line">scheme: Gemini</span><br></pre></td></tr></table></figure>

<p>   为博客添加<code>tags</code>，<code>about</code>，<code>categories</code>，<code>archives</code>等栏目，首先修改<code>/themes/next/_config.yml</code>的Menu节点，如下（删除原条目<code>||</code>及右边的内容），我们还可以启用缓存功能，使得博客加载速度提升。</p>
   <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">home: &#x2F;</span><br><span class="line">about: &#x2F;about&#x2F;</span><br><span class="line">tags: &#x2F;tags&#x2F;</span><br><span class="line">categories: &#x2F;categories&#x2F;</span><br><span class="line">archives: &#x2F;archives&#x2F;</span><br><span class="line"></span><br><span class="line">cache:</span><br><span class="line">  enable:true #speed up the loading</span><br></pre></td></tr></table></figure>
<p>   同时在根目录下依次执行下列命令生成对应的md模板，<br>   <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> hexo new page about</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> hexo new page tags</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> hexo new page categories</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> hexo new page archives</span></span><br></pre></td></tr></table></figure></p>
<p>   添加图片插件<code>hexo-easy-images</code>，该插件会自动将图片URL自动转储至项目的相对路径并且更新markdown的链接，</p>
<p>   注意：这个插件依赖<code>sharp</code>插件（10MB），因此安装过程比较慢，</p>
   <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm i hexo-easy-images -s</span><br></pre></td></tr></table></figure>

<p>   凑巧最近<code>github pages</code>出故障无法正常访问，因此，我们可以考虑使用国内的<code>gitee pages</code>来托管我们的静态博客，</p>
<p>   准备工作：</p>
<ol>
<li><p>创建一个<code>Gitee</code>帐号并且创建一个名为<code>hexoblog1</code>的空项目，不需要<code>.gitee.io</code>后缀（与<code>github</code>操作类似，这里不再讲述，开通<code>pages</code>功能需要绑定手机）</p>
</li>
<li><p>创建一个<code>Gitee</code>的<code>personal access token</code>，先保存token文本，下面有用（与<code>github</code>操作类似，这里不再讲述）参考见下：</p>
<p>[Gitee access token]: <a href="https://gitee.com/profile/personal_access_tokens3" target="_blank" rel="noopener">https://gitee.com/profile/personal_access_tokens3</a>.</p>
</li>
<li><p>在Travis-CI.com上添加一个<code>GITEE_TOKEN</code>的环境变量，将第2步的token文本填入Value字段，这样GITEE与Travis-CI的联系就可以建立了</p>
</li>
<li><p>修改<code>.travis.yml</code>配置如下，添加GITEE的推送地址即可，这样一来当更新提交时，<code>Travis-CI</code>会同时发布到<code>GITHUB</code>和<code>Gitee</code></p>
<p><strong>注意</strong>：GITEE PAGE的自动更新是收费的，因此每次发布博客完成之后，都需要登录<code>Gitee</code>手动来刷新页面，十分不方便，好在<code>Gitee</code>提供了第三方的API来支持自动更新。</p>
</li>
</ol>
<pre><code>[更新Pages语法]: https://gitee.com/api/v5/swagger#/postV5ReposOwnerRepoPagesBuilds
[授权Token语法]: http://git.mydoc.io/?t=180695
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">用户名，密码方式：</span></span><br><span class="line"><span class="string">git</span> <span class="string">clone</span> <span class="string">https://gitee.com/zxzllyj/sample-project.git</span></span><br><span class="line"><span class="string">根据提示输入用户名密码</span></span><br><span class="line">      </span><br><span class="line"><span class="string">username</span> <span class="string">+</span> <span class="string">accessToken</span> <span class="string">方式：</span></span><br><span class="line"><span class="string">git</span> <span class="string">clone</span> <span class="string">https://zxzllyj:fb63d3ae801d73d7364cd7b2cacxxxd2a@gitee.com/zxzllyj/sample-project.git</span></span><br><span class="line">      </span><br><span class="line"><span class="string">oauth2</span> <span class="string">+</span> <span class="string">accessToken</span> <span class="string">方式：</span></span><br><span class="line"><span class="string">git</span> <span class="string">clone</span> <span class="string">https://oauth2:fb63d3ae801d73d7364cd7b2cacxxxd2a@gitee.com/zxzllyj/sample-project.git</span></span><br></pre></td></tr></table></figure>

因此，最终的`yaml`如下：

<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">   <span class="attr">sudo:</span> <span class="literal">false</span></span><br><span class="line">   <span class="attr">language:</span> <span class="string">node_js</span></span><br><span class="line">   <span class="attr">node_js:</span></span><br><span class="line">     <span class="bullet">-</span> <span class="number">10</span> <span class="comment"># use nodejs v10 LTS</span></span><br><span class="line">   <span class="attr">cache:</span> <span class="string">npm</span></span><br><span class="line">   <span class="attr">branches:</span></span><br><span class="line">     <span class="attr">only:</span></span><br><span class="line">       <span class="bullet">-</span> <span class="string">master</span> <span class="comment"># build hexo branch only</span></span><br><span class="line">   <span class="attr">script:</span></span><br><span class="line">     <span class="bullet">-</span> <span class="string">hexo</span> <span class="string">generate</span> <span class="comment"># generate static files</span></span><br><span class="line"><span class="attr">after_script:</span></span><br><span class="line">     <span class="bullet">-</span> <span class="string">cd</span> <span class="string">./public</span></span><br><span class="line">     <span class="bullet">-</span> <span class="string">git</span> <span class="string">init</span></span><br><span class="line">     <span class="bullet">-</span> <span class="string">git</span> <span class="string">config</span> <span class="string">user.name</span> <span class="string">"Deployment Bot"</span></span><br><span class="line">     <span class="bullet">-</span> <span class="string">git</span> <span class="string">config</span> <span class="string">user.email</span> <span class="string">"deploy@travis-ci.org"</span></span><br><span class="line">     <span class="bullet">-</span> <span class="string">git</span> <span class="string">add</span> <span class="string">.</span></span><br><span class="line">     <span class="bullet">-</span> <span class="string">git</span> <span class="string">commit</span> <span class="string">-m</span> <span class="string">"deploy $&#123;GH_REPO&#125;"</span></span><br><span class="line">     <span class="bullet">-</span> <span class="string">git</span> <span class="string">config</span> <span class="string">--global</span> <span class="string">--unset</span> <span class="string">http.proxy</span></span><br><span class="line">     <span class="bullet">-</span> <span class="string">git</span> <span class="string">config</span> <span class="string">--global</span> <span class="string">--unset</span> <span class="string">https.proxy</span></span><br><span class="line">     <span class="bullet">-</span> <span class="string">git</span> <span class="string">push</span> <span class="string">--force</span> <span class="string">--quiet</span> <span class="string">"https://$&#123;GH_TOKEN&#125;@$&#123;GH_REPO&#125;"</span> <span class="string">master:master</span></span><br><span class="line">     <span class="bullet">-</span> <span class="string">git</span> <span class="string">push</span> <span class="string">--force</span> <span class="string">--quiet</span> <span class="string">"https://oauth2:$&#123;GITEE_TOKEN&#125;@$&#123;GITEE_REPO&#125;"</span> <span class="string">master:master</span></span><br><span class="line">     <span class="bullet">-</span> <span class="string">curl</span> <span class="string">-X</span> <span class="string">POST</span> <span class="string">https://oauth2:$&#123;GITEE_TOKEN&#125;@gitee.com/api/v5/repos/hexoblog1/hexoblog1/pages/builds</span></span><br><span class="line">   </span><br><span class="line">   <span class="attr">branches:</span></span><br><span class="line">     <span class="attr">only:</span></span><br><span class="line">       <span class="bullet">-</span> <span class="string">master</span></span><br><span class="line">   <span class="attr">env:</span></span><br><span class="line">    <span class="attr">global:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">GH_REPO:</span> <span class="string">github.com/hexoblog1/hexoblog1.github.io.git</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">GITEE_REPO:</span> <span class="string">gitee.com/hexoblog1/hexoblog1.git</span></span><br></pre></td></tr></table></figure></code></pre><p>   <strong>FAQ</strong></p>
<ol>
<li><p>能否将博客源文件和生成的页面都托管在Gitee ? </p>
<p>由于目当Travis-CI不支持与Gitee集成，如果需要使用Travis-CI的CICD功能，必须利用Github中转仓库</p>
</li>
</ol>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/07/20/%E7%BC%96%E7%A8%8B%E4%B9%8B%E7%BE%8E%E5%B0%86%E5%B8%85%E4%B8%8D%E7%85%A7%E9%9D%A2/" rel="next" title="编程之美将帅不照面">
                <i class="fa fa-chevron-left"></i> 编程之美将帅不照面
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/08/02/%E5%BD%92%E5%B9%B6%E6%8E%92%E5%BA%8F-%E6%B1%82%E9%80%86%E5%BA%8F%E6%95%B0%E7%AE%97%E6%B3%95/" rel="prev" title="归并排序-求逆序数算法">
                归并排序-求逆序数算法 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">LinRaise</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">2</span>
                  <span class="site-state-item-name">categories</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">tags</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">LinRaise</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

</body>
</html>
